package leetcode_701_800;

public class LeeCode_780 {
    public static void main(String[] args) {
        System.out.println(reachingPoints(1, 1, 3, 5));


        System.out.println(reachingPoints(1, 3, 1000000000, 3));
    }
    private static boolean reachingPoints(int sx, int sy, int tx, int ty) {
        while (tx != 0 && ty != 0 && (tx != sx || ty != sy)){
            if (tx >= ty){
                if (tx > sx){
                    int max = Math.max(sx, ty);
                    int t = (tx - max) / ty;
                    tx -= (t == 0 ? 1 : t) * ty;
                }else {
                    tx -= ty;
                }
            }else {
                if (ty > sy){
                    int max = Math.max(sy, tx);
                    int t = (ty - max) / tx;
                    ty -= (t == 0 ? 1 : t) * tx;
                }else {
                    ty -= tx;
                }
            }
        }
        return tx == sx && ty == sy;
    }
}